<template>
	<!-- 外面最大的div -->
	<view class="sideBox">
		<u-toast ref="uToast" />
		<view class="center">
			<!-- header -->
			<view class="header">
				<text class="txt1">发布活动</text>
				<navigator class="issBox" @click="add">
					<text>发布</text>	
				</navigator>
			</view>
			<!-- 发布内容和图片部分 -->
			<view class="section">
				<view class="content">
					<view class="title">
						 <input v-model="active_title" type="text" placeholder="输入标题..." />		
					</view>
					<!-- 选择部门 -->
					<view class="t1">
						<picker class="spopic" mode="selector" :range="sponsor" @change="spbox" value="index">
							<view>{{sponsor[index]==null?'请选择主办部门':sponsor[index]}}</view>
						</picker>
						<image class="img1" src="../../static/img/f11.png" mode=""></image>
					</view>
					<!-- 报名开始时间 -->
					<view class="t2">
						    <text>
								报名开始时间
							</text>
							<uni-datetime-picker v-model="active_start_time" type="date" :value="active_start_time"  @change="change1" />
					</view>
					<!-- 报名结束时间 -->
					<view class="t2">
						    <text>
								报名结束时间
							</text>
							<uni-datetime-picker type="date" v-model="active_end_time" :value="active_end_time"  @change="change2" />
					</view>
					<!-- 活动开始时间 -->
					<view class="t2">
						    <text>
								活动开始时间
							</text>
							<uni-datetime-picker v-model="registration_start_time" type="date" :value="registration_start_time"  @change="change3" />
					</view>
					<!-- 活动结束时间 -->
					<view class="t2">
						    <text>
								活动结束时间
							</text>
							<uni-datetime-picker v-model="registration_end_time" type="date" :value="registration_end_time"  @change="change4" />
					</view>
					<!-- 输入内容 -->
					<view class="con">
						<textarea v-model="active_details" @blur="bindTextAreaBlur" auto-height  placeholder="输入内容..."/>
					</view>
					
				</view>
			</view>
		</view>
		<!-- 上传图片  !!!函数未写 -->
		<view class="upload">
			<u-upload ref='uUpload' @on-uploaded='up1' :action="action" @on-success='up' :auto-upload='false' :file-list="fileList" :width='650' :height='350' ></u-upload>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			action:'http://172.17.26.211:3313//uploadFile',
			sponsor:['学生会','天地会','丐帮'],
			index:null,
			active_start_time:'',
			active_end_time:'',
			registration_start_time:'',
			registration_end_time:'',
			active_main_picture:'',
			active_details:'',
			active_title:'',
			address:'计算机学院体院馆',
		}
	},
	methods: {
		showToast() {
			this.$refs.uToast.show({
				title: '发布成功',
				type: 'success',
				// url: '/pages/activity/activity',
				// isTab:true,
				position:'top',
				
			});			
			wx.switchTab({
				url:'./activity',
				success(res) {
					let page= getCurrentPages().pop()
					
					page.onLoad();
				}
			})
		},
		bindTextAreaBlur: function (e) {
			console.log(e.detail.value)
		},
		spbox (e) {
			this.index = e.target.value;
		},
		change1(e) {
		                this.active_start_time = e
		                console.log('-change事件1:', e);
		},
		change2(e) {
		                this.active_end_time = e
		                console.log('-change事件2:', e);
		},
		change3(e) {
		                this.registration_start_time = e
		                console.log('-change事件3:', e);
		},
		change4(e) {
		                this.registration_end_time = e
		                console.log('-change事件4:', e);
		},
		up(data){
			// console.log(data.data);
			this.active_main_picture=data.data
			console.log(this.active_main_picture)
		},
		add(){
			this.$refs.uUpload.upload();
		},
		up1(lists){
			
			// this.active_start_time=this.$date(new Date(this.active_start_time))
			// this.active_end_time=this.$date(new Date(this.active_end_time))
			// this.registration_start_time=this.$date(new Date(this.registration_start_time))
			// this.registration_end_time=this.$date(new Date(this.registration_end_time))
			this.$http({
				url:'/activites/addCampusActivites',
				method:'post',
				data:{
					active_main_picture:this.active_main_picture,
					active_details:this.active_main_picture,
					active_id:1,
					active_title:this.active_title,
					address:this.address,
					status:0,
					active_start_time:this.active_start_time,
					active_end_time:this.active_end_time,
					registration_start_time:this.registration_start_time,
					registration_end_time:this.registration_end_time,
				}
			}).then((res)=>{
				console.log(res)
				this.showToast()
				// uni.navigateBack({})
			})
			
		}
	}
}
</script>

<style lang="less" scoped>
.sideBox {
	width: 750rpx;
	.center {
		width: 690rpx;
		margin: 0 auto;
		.header {	
			display: flex;
			justify-content: space-between;
			padding-top: 60rpx;
			height: 122rpx;
			.txt1 {
				font-size: 44rpx;
				font-weight: 600;
			}
			.issBox {
				width: 130rpx;
				height: 60rpx;
				line-height: 60rpx;
				border-radius: 30rpx;
				background-color: #f9cc66;
				text-align: center;
				
			}
		}
		.section {
			.content {
				.title{
					margin-top: 30rpx;
					height: 80rpx;
					line-height: 80rpx;
				}
				.t1{
					display: flex;
					.spopic{
						width: 650rpx;
						height: 80rpx;
						line-height: 80rpx;
					}
					.img1{
						width:80rpx;
						height: 80rpx;
						line-height: 80rpx;
					}
					
				}
				.t2{
					display: flex;
					justify-content: space-between;
					margin-top: 15rpx;
					margin-bottom: 15rpx;
					text{
						height: 80rpx;
						line-height: 80rpx;
					}
				}
				.con{
					margin-top: 20rpx;
					height: 80rpx;
					line-height: 80rpx;
				}
			}
		}
	}
}
.upload{
	display: flex;
	justify-content: center;
}
</style>

